/*
package 线程池案例;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

class MyThreadPool {
    private BlockingQueue<Runnable> queue = new LinkedBlockingQueue<>();
    private int threadMAX = 5;//最大工作线程数
    //存放/提交 任务
    public void submit(Runnable task) {
        queue.add(task);
    }
    //预设提供线程来进行工作
    public MyThreadPool() {
        for(int i = 0; i < threadMAX; i++) {
            Thread t = new Thread(new Runnable() {
                @Override
                public void run() {
                    while(true){
                        try {
                            queue.take().run();
                            System.out.println("线程" + Thread.currentThread().getName() + "开始工作");
                            Thread.sleep(3000);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }
            });
            t.start();
        }
    }
}

public class Test2 {
    public static void main(String[] args){
        MyThreadPool myThreadPool = new MyThreadPool();
        for(int i = 0; i < 100; i++){
            int task = i;
            myThreadPool.submit(new Runnable() {
                @Override
                public void run() {
                    System.out.println("任务:" + task + "已完成");
                }
            });
        }
    }
}
*/
